{namespace be=TYPO3\CMS\Backend\ViewHelpers}

<f:layout name="Permission" />

<f:section name="headline">
    <h1>
        <f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:permissions" />:
        <f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:Edit" />
    </h1>
</f:section>

<f:section name="content">
    <f:form action="update" name="editform" id="PermissionControllerEdit">

        <div class="form-group">
            <label><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:Owner" /></label>
            <f:form.select name="data[pages][{id}][perms_userid]" options="{beUserData}" value="{currentBeUser}" class="form-control" />
        </div>

        <div class="form-group">
            <label><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:Group" /></label>
            <f:if condition="{f:count(subject:beGroupData)} > 1">
                <f:then>
                    <f:form.select name="data[pages][{id}][perms_groupid]" options="{beGroupData}" value="{currentBeGroup}" class="form-control" />
                </f:then>
                <f:else>
                    <div class="alert alert-notice"><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:noGroups" /></div>
                </f:else>
            </f:if>
        </div>

        <div class="panel panel-default panel-space">
            <div class="table-fit">
                <table class="table table-striped table-hover" id="typo3-permissionMatrix">
                    <thead>
                        <tr>
                            <th></th>
                            <th><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:1" /></th>
                            <th><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:16" /></th>
                            <th><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:2" /></th>
                            <th><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:4" /></th>
                            <th><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:8" /></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><strong><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:Owner" /></strong></td>
                            <td><input type="checkbox" name="check[perms_user][1]" data-check-change-permissions="check[perms_user],tx_beuser_system_beusertxpermission[data][pages][{id}][perms_user]" /></td>
                            <td><input type="checkbox" name="check[perms_user][5]" data-check-change-permissions="check[perms_user],tx_beuser_system_beusertxpermission[data][pages][{id}][perms_user]" /></td>
                            <td><input type="checkbox" name="check[perms_user][2]" data-check-change-permissions="check[perms_user],tx_beuser_system_beusertxpermission[data][pages][{id}][perms_user]" /></td>
                            <td><input type="checkbox" name="check[perms_user][3]" data-check-change-permissions="check[perms_user],tx_beuser_system_beusertxpermission[data][pages][{id}][perms_user]" /></td>
                            <td><input type="checkbox" name="check[perms_user][4]" data-check-change-permissions="check[perms_user],tx_beuser_system_beusertxpermission[data][pages][{id}][perms_user]" /></td>
                        </tr>
                        <tr>
                            <td><strong><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:Group" /></strong></td>
                            <td><input type="checkbox" name="check[perms_group][1]" data-check-change-permissions="check[perms_group],tx_beuser_system_beusertxpermission[data][pages][{id}][perms_group]" /></td>
                            <td><input type="checkbox" name="check[perms_group][5]" data-check-change-permissions="check[perms_group],tx_beuser_system_beusertxpermission[data][pages][{id}][perms_group]" /></td>
                            <td><input type="checkbox" name="check[perms_group][2]" data-check-change-permissions="check[perms_group],tx_beuser_system_beusertxpermission[data][pages][{id}][perms_group]" /></td>
                            <td><input type="checkbox" name="check[perms_group][3]" data-check-change-permissions="check[perms_group],tx_beuser_system_beusertxpermission[data][pages][{id}][perms_group]" /></td>
                            <td><input type="checkbox" name="check[perms_group][4]" data-check-change-permissions="check[perms_group],tx_beuser_system_beusertxpermission[data][pages][{id}][perms_group]" /></td>
                        </tr>
                        <tr>
                            <td><strong><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:Everybody" /></strong></td>
                            <td><input type="checkbox" name="check[perms_everybody][1]" data-check-change-permissions="check[perms_everybody],tx_beuser_system_beusertxpermission[data][pages][{id}][perms_everybody]" /></td>
                            <td><input type="checkbox" name="check[perms_everybody][5]" data-check-change-permissions="check[perms_everybody],tx_beuser_system_beusertxpermission[data][pages][{id}][perms_everybody]" /></td>
                            <td><input type="checkbox" name="check[perms_everybody][2]" data-check-change-permissions="check[perms_everybody],tx_beuser_system_beusertxpermission[data][pages][{id}][perms_everybody]" /></td>
                            <td><input type="checkbox" name="check[perms_everybody][3]" data-check-change-permissions="check[perms_everybody],tx_beuser_system_beusertxpermission[data][pages][{id}][perms_everybody]" /></td>
                            <td><input type="checkbox" name="check[perms_everybody][4]" data-check-change-permissions="check[perms_everybody],tx_beuser_system_beusertxpermission[data][pages][{id}][perms_everybody]" /></td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>

        <div class="form-group">
            <label for="recursionLevel"><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:Depth" /></label>
            <f:form.select id="recursionLevel" name="mirror[pages][{id}]" options="{recursiveSelectOptions}" class="form-control" />
        </div>

        <f:form.hidden name="data[pages][{id}][perms_user]" value="{pageInfo.perms_user}" />
        <f:form.hidden name="data[pages][{id}][perms_group]" value="{pageInfo.perms_group}" />
        <f:form.hidden name="data[pages][{id}][perms_everybody]" value="{pageInfo.perms_everybody}" />
        <f:form.hidden name="depth" value="{depth}" />
        <f:form.hidden name="returnUrl" value="{returnUrl}" />

    </f:form>

    <hr>
    <h3><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:Legend" /></h3>
    <p>
        <strong><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:1" /></strong>: <f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:1_t" /> <br />
        <strong><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:16" /></strong>: <f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:16_t" /> <br />
        <strong><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:2" /></strong>: <f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:2_t" /> <br />
        <strong><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:4" /></strong>: <f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:4_t" /> <br />
        <strong><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:8" /></strong>: <f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:8_t" />
    </p>
    <p><f:translate key="LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:def" /></p>

    <script>
        require(["jquery", "TYPO3/CMS/Beuser/Permissions"], function($, Permissions) {
            Permissions.setCheck("check[perms_user]", "tx_beuser_system_beusertxpermission[data][pages][{id}][perms_user]");
            Permissions.setCheck("check[perms_group]", "tx_beuser_system_beusertxpermission[data][pages][{id}][perms_group]");
            Permissions.setCheck("check[perms_everybody]", "tx_beuser_system_beusertxpermission[data][pages][{id}][perms_everybody]");
        });
    </script>

</f:section>
